package com.jsmile.cloud.msgcenter.zf.strategy.factory;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;

import com.jsmile.cloud.msgcenter.zf.strategy.interfaces.IAlilNotify;

import lombok.extern.slf4j.Slf4j;

/**
 * @author xiao
 * @since 2021/5/30
 */
@Service
@Slf4j
public class AliNotifyFactory implements ApplicationContextAware {
    private final Map<String, IAlilNotify> notifyMap = new HashMap<>(10);

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, IAlilNotify> beansOfType = applicationContext.getBeansOfType(IAlilNotify.class);
        beansOfType.forEach((s, promotion) -> notifyMap.putIfAbsent(promotion.getNotifyType(), promotion));
    }

    public IAlilNotify findStrategy(String type) {
        return notifyMap.get(type);
    }
}
